import java.util.HashSet;
import java.util.Set;

/**
 * @author HikaruZhang
 *
 */
class Emp extends HashSet
{
	protected int age ;
	
	
	/** 
	 * Override hashcode
	 * @return The hashcode of the age;
	 */
	@Override
	
	public int hashCode() {
//		final int prime = 31;
//		int result = 1;
//		result = prime * result + age;
//		return result;
		return this.age;
	}
	/** 
	 * Override equals
	 * Determine whether two age is equal;
	 * @return True if equal;
	 */
	@Override
	
	public boolean equals(Object obj) {
//		if (this == obj) {
//			return true;
//		}
//		if (obj == null) {
//			return false;
//		}
//		if (getClass() != obj.getClass()) {
//			return false;
//		}
//		Emp other = (Emp) obj;
//		if (this.age != other.age) {
//			return false;
//		}
//		return true;
		if(this == obj){
			return true;
		}
		Emp another = (Emp) obj;
		if(this.age == another.age){
			return true;
		}
		return false;
	}

	public Emp( int age )
	{
		super();
		this.age = age;
	}
	
	
}
public class HashCodeandEquals {
	public static void main(String[] args) 
	{
		Emp emp1 = new Emp(23);
		Emp emp2 = new Emp(24);
		Emp emp3 = new Emp(25);
		Emp emp4 = new Emp(26);
		Emp emp5 = new Emp(27);
		HashSet<Emp> hs = new HashSet<Emp>();
		hs.add(emp1);
		hs.add(emp2);
		hs.add(emp3);
		hs.add(emp4);
		hs.add(emp5);
		
		System.out.println("HashSet Size--->>>"+hs.size());
		System.out.println("hs.contains( new Emp(25))--->>>"+hs.contains(new Emp(25)));//if not override hashcode and equals return false because the newed object here has different memory address.
		System.out.println("hs.remove( new Emp(24)--->>>"+hs.remove( new Emp(25)));
		System.out.println("Now HashSet Size--->>>"+hs.size());
	}

}
